package com.example.ipservice;

import org.springframework.context.annotation.Profile;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
public class HealthController {
    private volatile boolean serviceHealthy = true;

    @GetMapping("/health/123")
    public ResponseEntity<String> healthCheck() {
        return serviceHealthy
                ? ResponseEntity.ok("200")  // 返回数字200表示正常
                : ResponseEntity.status(503).body("0");  // 返回0表示异常
    }

    @PostMapping("/health/toggle")
    public String toggleHealth() {
        serviceHealthy = !serviceHealthy;
        return "当前健康状态: " + (serviceHealthy ? "正常" : "异常");
    }
}